<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Auth;
use Illuminate\Validation\Rule;

class UserUpdate extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array<string, mixed>
     */
    public function rules()
    {
        return [
            'name' => [
                'required',
                'between:1,30',
                'regex:/^[\x{4e00}-\x{9fa5}A-za-z0-9\_\-]+$/u',//中文
                Rule::unique('users')->ignore(Auth::id())//自己排除在外
            ],
            'email' => ['required','email'],
            'info'  => ['between:2,200'],
            'avatar'  => ['mimes:jpg,png,gif,jpeg','dimensions:min_width=300,min_height=300','max:2048',],
        ];
    }

    public function messages()
    {
        return [
            'avatar.dimensions' => '头像图片最小尺寸为300x300',
            'avatar.max' => '头像图片最多2MB',
        ];
    }

    public function attributes()
    {
        return [
            'name' => "用户名",
            'email' => "邮箱",
            'info' => "个人简介",
            'avatar' => "用户头像",
        ];
    }
}
